<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 6.2.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.3/css/all.min.css" integrity="sha256-2H3fkXt6FEmrReK448mDVGKb3WW2ZZw35gI7vqHOE4Y=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"singingxy.github.io","root":"/","images":"/images","scheme":"Gemini","version":"8.6.1","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"}}</script><script src="/js/config.js"></script>
<meta name="description" content="为什么选 hexoGitHub Pages 的配置页面里推荐了 Jekyll，本来打算就从 Jekyll 开始摸索的，去主页看了文档，需要 Ruby 和 RubyGems ，光是下载 Ruby 这一步就把我卡住了，下载速度为 0。行吧。只能把目光转向了 hexo，一看环境只需要 node.js，用 npm 直接安装就可以，太方便了。">
<meta property="og:type" content="article">
<meta property="og:title" content="来用hexo和GitHub Pages做个个人博客吧">
<meta property="og:url" content="https://singingxy.github.io/2019/%E6%9D%A5%E7%94%A8hexo%E5%92%8CGitHub%20Pages%E5%81%9A%E4%B8%AA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2%E5%90%A7/index.html">
<meta property="og:site_name" content="sing&#39;s blog">
<meta property="og:description" content="为什么选 hexoGitHub Pages 的配置页面里推荐了 Jekyll，本来打算就从 Jekyll 开始摸索的，去主页看了文档，需要 Ruby 和 RubyGems ，光是下载 Ruby 这一步就把我卡住了，下载速度为 0。行吧。只能把目光转向了 hexo，一看环境只需要 node.js，用 npm 直接安装就可以，太方便了。">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2019-11-25T07:12:38.000Z">
<meta property="article:modified_time" content="2019-11-25T07:12:38.000Z">
<meta property="article:author" content="Sing">
<meta property="article:tag" content="hexo">
<meta property="article:tag" content="blog">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://singingxy.github.io/2019/%E6%9D%A5%E7%94%A8hexo%E5%92%8CGitHub%20Pages%E5%81%9A%E4%B8%AA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2%E5%90%A7/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://singingxy.github.io/2019/%E6%9D%A5%E7%94%A8hexo%E5%92%8CGitHub%20Pages%E5%81%9A%E4%B8%AA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2%E5%90%A7/","path":"/2019/来用hexo和GitHub Pages做个个人博客吧/","title":"来用hexo和GitHub Pages做个个人博客吧"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>来用hexo和GitHub Pages做个个人博客吧 | sing's blog</title>
  




  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">sing's blog</h1>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">C'est La Vie Mon Ami.</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>







</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E4%B8%BA%E4%BB%80%E4%B9%88%E9%80%89-hexo"><span class="nav-number">1.</span> <span class="nav-text">为什么选 hexo</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%BC%80%E5%A7%8B%E5%AE%89%E8%A3%85"><span class="nav-number">2.</span> <span class="nav-text">开始安装</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E9%83%A8%E7%BD%B2%E5%88%B0-GitHub-Pages"><span class="nav-number">3.</span> <span class="nav-text">部署到 GitHub Pages</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%8F%91%E5%87%BA%E7%AC%AC%E4%B8%80%E7%AF%87%E6%96%87%E7%AB%A0"><span class="nav-number">4.</span> <span class="nav-text">发出第一篇文章</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E4%BD%BF%E7%94%A8%E5%8F%A6%E4%B8%80%E4%B8%AA%E5%88%86%E6%94%AF%E4%BF%9D%E5%AD%98%E6%BA%90%E7%A0%81"><span class="nav-number">5.</span> <span class="nav-text">使用另一个分支保存源码</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%BC%80%E5%A7%8B%E5%86%99%E6%96%87%E7%AB%A0%E5%95%A6"><span class="nav-number">6.</span> <span class="nav-text">开始写文章啦</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E4%BD%BF%E7%94%A8%E6%9C%AC%E5%9C%B0%E5%9B%BE%E7%89%87%E6%8F%92%E4%BB%B6-hexo-asset-image"><span class="nav-number">7.</span> <span class="nav-text">使用本地图片插件 hexo-asset-image</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-overview">
            <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">Sing</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives">
          <span class="site-state-item-count">18</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
        <span class="site-state-item-count">2</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
        <span class="site-state-item-count">25</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



          </div>
        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://singingxy.github.io/2019/%E6%9D%A5%E7%94%A8hexo%E5%92%8CGitHub%20Pages%E5%81%9A%E4%B8%AA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2%E5%90%A7/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Sing">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="sing's blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          来用hexo和GitHub Pages做个个人博客吧
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2019-11-25 15:12:38" itemprop="dateCreated datePublished" datetime="2019-11-25T15:12:38+08:00">2019-11-25</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E7%AC%94%E8%AE%B0/" itemprop="url" rel="index"><span itemprop="name">笔记</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h4 id="为什么选-hexo"><a href="#为什么选-hexo" class="headerlink" title="为什么选 hexo"></a>为什么选 hexo</h4><p>GitHub Pages 的配置页面里推荐了 Jekyll，本来打算就从 Jekyll 开始摸索的，去主页看了文档，需要 Ruby 和 RubyGems ，光是下载 Ruby 这一步就把我卡住了，下载速度为 0。行吧。<br>只能把目光转向了 hexo，一看环境只需要 node.js，用 npm 直接安装就可以，太方便了。</p>
<span id="more"></span>

<h4 id="开始安装"><a href="#开始安装" class="headerlink" title="开始安装"></a>开始安装</h4><p>先把 hexo 装上</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install -g hexo-cli</span><br></pre></td></tr></table></figure>

<p>然后用 init 初始化</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">hexo init &lt;folder&gt;</span><br><span class="line"><span class="built_in">cd</span> &lt;folder&gt;</span><br><span class="line">npm install</span><br></pre></td></tr></table></figure>

<p>别看就这么短短 3 句话，也有的折腾的。<br>init 这一步由于要下载一个默认的主题包，文件还不小，下了一会儿速度就变 0 了，继续等，结果直接超时了，报了一堆错，基本就是说下载失败什么的。只能重新开始又下了一遍，耐心等待，这回终于成功了。</p>
<p><code>_config.yml</code>是配置文件，自定义的属性就在里面设置。</p>
<h4 id="部署到-GitHub-Pages"><a href="#部署到-GitHub-Pages" class="headerlink" title="部署到 GitHub Pages"></a>部署到 GitHub Pages</h4><p>到<code>_config.yml</code>文件里拉到最下面找到 deploy 配置：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">deploy:</span></span><br><span class="line">  <span class="attr">type:</span> <span class="string">git</span></span><br><span class="line">  <span class="attr">repo:</span> <span class="string">https://github.com/singingXY/singingXY.github.io.git</span></span><br><span class="line">  <span class="attr">branch:</span> <span class="string">master</span></span><br></pre></td></tr></table></figure>

<p>填上自己的仓库地址和分支名就可以使用了。</p>
<h4 id="发出第一篇文章"><a href="#发出第一篇文章" class="headerlink" title="发出第一篇文章"></a>发出第一篇文章</h4><p>下面是几个常用的命令，步骤是：新建文章-生成-本地预览-部署到线上</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">hexo n <span class="string">&quot;xxx&quot;</span> == hexo new  <span class="string">&quot;xxx&quot;</span>   <span class="comment">#新建文章</span></span><br><span class="line">hexo g == hexo generate           <span class="comment">#生成</span></span><br><span class="line">hexo s == hexo server             <span class="comment">#启动服务预览</span></span><br><span class="line">hexo d == hexo deploy             <span class="comment">#部署</span></span><br></pre></td></tr></table></figure>

<p>除了上面的写法，我们在自动生成的<code>package.json</code>文件里可以看到如下配置，</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&quot;scripts&quot;: &#123;</span><br><span class="line">  &quot;build&quot;: &quot;hexo generate&quot;,</span><br><span class="line">  &quot;clean&quot;: &quot;hexo clean&quot;,</span><br><span class="line">  &quot;deploy&quot;: &quot;hexo deploy&quot;,</span><br><span class="line">  &quot;server&quot;: &quot;hexo server&quot;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>习惯 npm 的也可以用<code>npm run</code>的形式写。</p>
<h4 id="使用另一个分支保存源码"><a href="#使用另一个分支保存源码" class="headerlink" title="使用另一个分支保存源码"></a>使用另一个分支保存源码</h4><p>由于<code>master</code>分支里保存的是我们生成出来的文件，而源码是存在本地的，为了当我换一台电脑也能继续更新，我需要把源码存到 github 里，所以新建了一个<code>hexo</code>分支，把源码存在里面。这样当我源码有改动时也能同步更新了。</p>
<h4 id="开始写文章啦"><a href="#开始写文章啦" class="headerlink" title="开始写文章啦"></a>开始写文章啦</h4><p>当我们执行<code>hexo new</code>的命令后，会在 source 文件夹下看到我们新建的<code>.md</code>文件，顶端以<code>---</code>分隔的区域，叫做 Front-matter，我们可以在里面配置这篇文章的信息。<br>如果要给文章添加 tags 和分类，可以如下设置</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">categories:</span></span><br><span class="line">  <span class="bullet">-</span> <span class="string">Diary</span></span><br><span class="line"><span class="attr">tags:</span></span><br><span class="line">  <span class="bullet">-</span> <span class="string">PS3</span></span><br><span class="line">  <span class="bullet">-</span> <span class="string">Games</span></span><br></pre></td></tr></table></figure>

<p>Front-matter 的下面就可以开始用 markdown 的语法写文章了。</p>
<h4 id="使用本地图片插件-hexo-asset-image"><a href="#使用本地图片插件-hexo-asset-image" class="headerlink" title="使用本地图片插件 hexo-asset-image"></a>使用本地图片插件 hexo-asset-image</h4><p>先将<code>_config.yml</code>的<code>post_asset_folder</code>改为 true，然后运行以下命令：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install https://github.com/xcodebuild/hexo-asset-image --save</span><br></pre></td></tr></table></figure>

<p>这样可以解决在使用本地图片时，本地图片和线上图片路径不一致的问题，本地预览时也可以显示出图片。<br>而且不用把分散的文章里的图片都放在一个总的 source 文件夹内，而是按照文章目录来放置，简单明了。</p>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/hexo/" rel="tag"># hexo</a>
              <a href="/tags/blog/" rel="tag"># blog</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2019/hello-world/" rel="prev" title="Hello World">
                  <i class="fa fa-chevron-left"></i> Hello World
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2019/WIN10%E5%BC%80%E6%9C%BA%E5%86%85%E5%AD%98%E5%8D%A0%E7%94%A8%E8%BF%87%E9%AB%98/" rel="next" title="WIN10开机内存占用过高">
                  WIN10开机内存占用过高 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Sing</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script>

  




  





</body>
</html>
